// approval/pages/approval_center/approval_center.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isMusk: false,
    examMainNum: 0,
    copyExamMainNum: 0,
    departmentId: '',
    listA: [{
      img: '/approval/img/listImg/vacate_approval.png',
      text: '请假申请',
      types: 0,
      show: false
    }, {
      img: '/approval/img/listImg/items_approval.png',
      text: '物料申请',
      types: 1,
      show: false
    }, {
      img: '/approval/img/listImg/leave_apply.png',
      text: '离职申请',
      types: 2,
      show: false
    }, {
      img: '/approval/img/listImg/no_approval.png',
      text: '销假申请',
      types: 3,
      show: false
    }, {
      img: '/approval/img/listImg/positive_apply.png',
      text: '转正申请',
      types: 4,
      show: false
    }, {
      img: '/approval/img/listImg/items_return.png',
      text: '物料归还',
      types: 5,
      show: false
    }, {
      img: '/approval/img/listImg/person_apply.png',
      text: '人员需求',
      types: 6,
      show: false
    }, ],

  },

  getData() {
    var url = app.globalData.url + 'exam/getExamMainPage',
      that = this,
      copyExamMainNum = '',
      examMainNum = '',
      listA = that.data.listA;

    wx.showLoading({
      title: '',
      icon: ''
    })
    app.wxRequest(url, {
      memberId: app.globalData.memberId,
      departmentId: that.data.departmentId
    }, res => {
      if (res.flag) {
        if (res.flag) {
          copyExamMainNum = res.data.copyExamMainNum;
          examMainNum = res.data.examMainNum;
          for (var i in listA) {
            for (var j in res.data.types) {
              if (listA[i].show == res.data.types[j]) {
                listA[i].show = true
              }
            }
          }
          wx.hideLoading()
          wx.stopPullDownRefresh()
          that.setData({
            copyExamMainNum,
            examMainNum,
            listA
          })
        }
      }
    })
  },
  toPage(e) {
    console.log(e);
    var nav = e.currentTarget.dataset.nav.text;
    if (nav == "请假申请") {
      wx.navigateTo({
        url: '/approval/pages/leave_approval/leave_approval',
      })
    } else if (nav == '物料申请') {
      wx.navigateTo({
        url: '/approval/pages/items_approval/items_approval',
      })
    } else if (nav == '离职申请') {
      wx.navigateTo({
        url: '/approval/pages/depart_approval/depart_approval',
      })
    } else if (nav == '销假申请') {
      wx.navigateTo({
        url: '/approval/pages/report_approval/report_approval',
      })
    } else if (nav == '物料归还') {
      wx.navigateTo({
        url: '/approval/pages/itemsReturn_approval/itemsReturn_approval',
      })
    } else if (nav == '转正申请') {
      wx.navigateTo({
        url: '/approval/pages/positive_apply/positive_apply',
      })
    } else if (nav == '人员需求') {
      wx.navigateTo({
        url: '/approval/pages/person_apply/person_apply',
      })
    }
  },
  toPageHandle(e) {
    var nav = e.currentTarget.dataset.nav;
    if (nav == 'myApproval') {
      wx.navigateTo({
        url: '/managers/pages/my_approval/my_approval',
      })
    } else if (nav == 'callMe') {
      wx.navigateTo({
        url: '/managers/pages/copy_me/copy_me',
      })
    } else if (nav == 'all') {
      wx.navigateTo({
        url: '/managers/pages/approvalAll/approvalAll',
      })
    }
  },



  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(app.globalData);

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      departmentId: app.globalData.departmentId
    })
    this.getData()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.getData()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})